from django.shortcuts import render
from django.http import HttpResponse
from book.models import BookInfo, Weapon, Skill
from django.views import View

import json


def test(request):
    return HttpResponse('测试django')


def index(request):
    context = {'header': '模板数据'}
    return render(request, 'book/index.html', context)


def book(request):
    books = BookInfo.objects.all()
    print(books)
    context = {'books': books}
    print(context)
    return render(request, 'book/booklist.html', context)

def weapon(request):
    weapons = Weapon.objects.all()
    print(weapons)
    context = {'weapons': weapons}
    print(context)
    return render(request, 'book/weapon.html', context)


def skill(request):
    skill = Skill.objects.all()
    print(skill)
    context = {'skill': skill}
    print(context)
    return render(request, 'book/skill.html', context)

def detail(request, cat_id, book_id):
   # print(cat_id, book_id)
   #query_param = request.GET.getlist('username')
   #print(query_param)
   #data = request.POST
   data = request.body
   data_str = data.decode()
   #decode_data =decode(data_srt)
   dict =json.loads(data_str)
   print(dict)
   print(type(dict))
   dict2 = json.dumps(data_str)
   print(dict2)
   print(type(dict2))

   return HttpResponse('detail')


def set_cookie(request):

     username = request.GET.get('username')
     response = HttpResponse('set_cookie')
     response.set_cookie('username', username)
     return  HttpResponse('cookie')


# Create your views here.